package com.maxmlr.music.admin.service.impl;

import com.google.common.collect.Lists;
import com.maxmlr.music.admin.dao.DeptMapper;
import com.maxmlr.music.admin.entity.Dept;
import com.maxmlr.music.admin.param.TreeParam;
import com.maxmlr.music.admin.service.DeptService;
import com.maxmlr.music.admin.service.transfer.DeptTransfer;
import com.maxmlr.music.admin.util.BuildTreeParam;
import com.maxmlr.music.common.base.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author max
 * @version 1.0
 * @ClassName DeptServiceImpl
 * @Description  部门管理  服务实现类
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-14
 */
@Slf4j
@Service
public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    private DeptTransfer deptTransfer;

    @Override
    public TreeParam<Dept> getTreeParam() {
        List<TreeParam<Dept>> trees = Optional.ofNullable(list())
                .orElse(Lists.newArrayList())
                .stream()
                .map(p -> deptTransfer.po2TreeParam(p))
                .collect(Collectors.toList());
        return BuildTreeParam.build(trees);
    }

}
